package com.moore.service.Impl;

import com.moore.bean.Permissions;
import com.moore.dto.ResponseData;
import com.moore.mapper.RolePermissionMapper;
import com.moore.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.moore.utils.Logger.toLog;
@Service
public class RolePermissionServiceImpl implements RolePermissionService {
    @Autowired
    RolePermissionMapper rolePermissionMapper;
    @Override
    public ResponseData getPermissionsByRoleId(int roleId) {
        toLog("获取角色ID为"+roleId+"的权限成功");
        List<Permissions> permissions = rolePermissionMapper.getPermissionsByRoleId(roleId);
        return new ResponseData(200,"获取成功",permissions,0);
    }

    @Override
    public ResponseData updateRolePermissions(int roleId, List<Integer> permissionIds) {
        toLog("更新角色ID为"+roleId+"的权限成功");
        rolePermissionMapper.deletePermissionsByRoleId(roleId);
        for (Integer permissionId : permissionIds) {
            rolePermissionMapper.insertRolePermission(roleId, permissionId);
        }
        return new ResponseData(200,"更新成功",null,0);
    }
}
